package main

import "fmt"

type stu struct {
	id   int
	name string
}

func main() {
	a := stu{1, "zs"}

	var p *stu
	p = &a
	fmt.Printf("%T\n", p) //output:*main.stu

	p1 := &a
	fmt.Printf("%T\n", p1) //output:*main.stu
	fmt.Printf("%v\n", p1) //&{1 zs}

	//通过结构体指针间接操作结构体成员
	(*p1).name = "foo"
	fmt.Println(a)

	//通过指针可以直接操作结构体成员
	p1.id = 2
	fmt.Println(a)

	test()
}

func test() {
	//结构体切片
	var a []stu
	//结构体切片指针
	p := &a

	*p = append(*p, stu{1, "zs"})
	fmt.Println(a)

	var b []stu = make([]stu, 3)
	p1 := &b
	(*p1)[0] = stu{1, "zs"}
	(*p1)[1] = stu{2, "ls"}
	(*p1)[2] = stu{2, "ls"}
	fmt.Println(b)
}
